package io.adrainty.bolee.framework.commons.user;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.adrainty.bolee.framework.commons.basic.BaseEntity;
import io.adrainty.bolee.framework.commons.basic.EnableEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.io.Serial;
import java.util.Set;

/**
 * <p>UserEntity</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description UserEntity
 * @since 2025/8/1 11:25:31
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(description = "用户实体")
public class UserEntity extends BaseEntity {

    @Serial
    private static final long serialVersionUID = 2832421194123813350L;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "密码")
    private String password;

    @Schema(description = "昵称")
    private String nickName;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "客户端")
    private String clientId;

    @Schema(description = "真实姓名")
    private String realName;

    @Schema(description = "手机号码")
    private String mobile;

    @Schema(description = "用户性别（0男 1女 2未知）")
    private String sex;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "三方openId")
    private String openId;

    @Schema(description = "查询用户：用户角色主键集合")
    private Set<String>  roleVOIds;

    @Schema(description = "查询用户：所属部门职位")
    private Set<DeptPostUserEntity>  deptPostUserVOs;

    @Schema(description = "构建令牌：用户角色标识")
    private Set<String> roleLabels;

    @Schema(description = "构建令牌：用户权限路径")
    private Set<String> resourceRequestPaths;

    @Schema(description = "用户令牌")
    private String userToken;

    @Schema(description = "数据权限")
    private DataSecurityEntity dataSecurityVO;

    @Schema(description = "部门编号【查询关联】")
    private String deptNo;

    @Schema(description = "职位编号【查询关联】")
    private String postNo;

    @Schema(description = "角色主键【查询关联】")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long roleId;

    @Schema(description = "只做请求认证,客户只需请求认证，员工除请求认证，还需访问授权")
    private Boolean onlyAuthenticate ;

    @Schema(description = "企业编号")
    private String companyNo;

    @Schema(description = "数据状态：0正常 1禁用")
    private EnableEnum dataState;

    /**
     * 脱敏数据
     */
    public void desensitize() {
        this.password = null;
        this.mobile = DesensitizedUtil.mobilePhone(this.mobile);
        this.email = DesensitizedUtil.email(this.email);
    }

}
